package com.glodon.paas.document.dao.domain;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.glodon.paas.document.api.bean.ProjectMember;
import com.glodon.paas.document.service.util.DocumentBuilder;
import com.glodon.paas.util.BeanFactoryUtil;
import com.google.code.morphia.annotations.Id;

public class ProjectMemberEntity {
    public static DocumentBuilder builder = null;
    public static ProjectMember getDto(ProjectMemberEntity e) {
        return getDto(e,false);
    }
    public static ProjectMember getDto(ProjectMemberEntity e,boolean cascade) {
        if (e == null) {
            return null;
        } else {
            ProjectMember d = new ProjectMember();
            d.setId(e.getId());
            d.setProjectId(e.getProjectId());
            d.setRoleId(e.getRoleId());
            d.setStatus(e.getStatus());
            d.setMemberType(e.getMemberType());
            d.setGroupId(e.getGroupId());
            d.setCreateTime(e.getCreateTime());
            d.setUpdateTime(e.getUpdateTime());
            d.setUserId(e.getUserId());
            d.setIsOrg(e.getIsOrg());
            d.setEditable(e.getEditable());
            d.setMemberId(e.getMemberId());
            if (cascade) {
                if (builder == null) {
                    builder = BeanFactoryUtil.getBean(DocumentBuilder.class);
                }
                d.setOwner(builder.buildUser(e.getUserId()));
            }
            return d;
        }
    }
    public static List<ProjectMember> getDtos(List<ProjectMemberEntity> es) {
        return getDtos(es,false);
    }
    public static List<ProjectMember> getDtos(List<ProjectMemberEntity> es,boolean cascade) {
        if (es == null) {
            return null;
        } else {
            List<ProjectMember> ds = new ArrayList<ProjectMember>(es.size());
            for (ProjectMemberEntity e : es) {
                ds.add(getDto(e,cascade));
            }
            return ds;
        }
    }

    @Id
    private String id;
    private String userId;
    private String roleId;
    // 0:invited;1:accepted;2:removed;
    private int    status;
    // 0:common user;1:group
    private int    memberType;
    private String groupId;
    private String projectId;
    private Date   createTime;
    private Date   updateTime;
    private int editable=0;
    private int isOrg=0;
    private String memberId;
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getRoleId() {
        return roleId;
    }

    public void setRoleId(String roleId) {
        this.roleId = roleId;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getProjectId() {
        return projectId;
    }

    public void setProjectId(String projectId) {
        this.projectId = projectId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public int getMemberType() {
        return memberType;
    }

    public void setMemberType(int memberType) {
        this.memberType = memberType;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }
    
    public int getEditable() {
        return editable;
    }
    
    public void setEditable(int editable) {
        this.editable = editable;
    }
    
    public String getMemberId() {
        return memberId;
    }
    
    public void setMemberId(String memberId) {
        this.memberId = memberId;
    }
    
    public int getIsOrg() {
        return isOrg;
    }
    
    public void setIsOrg(int isOrg) {
        this.isOrg = isOrg;
    }
}
